package com.bxl.netty.rpc.client.handler;

import com.bxl.netty.rpc.client.common.register.CallBackRegister;
import com.bxl.netty.rpc.common.context.Context;
import com.bxl.netty.rpc.common.message.MsgResponseContent;
import com.bxl.netty.rpc.common.message.PackageMsg;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;


/**
 * <>
 *
 * @author baixl
 * @date 2021/2/23
 */
public class ClientHandler extends SimpleChannelInboundHandler<PackageMsg<MsgResponseContent>> {
    private Context context;
    public ClientHandler(Context context) {
        this.context =context;
    }

    protected void channelRead0(ChannelHandlerContext channelHandlerContext, PackageMsg<MsgResponseContent> message) throws Exception {
        System.out.println(message.getContent().getContent());
        CallBackRegister.runCallBack(message);
    }

    public void channelInactive(ChannelHandlerContext ctx) throws Exception{
        System.out.println("aaa");
    }

    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
            throws Exception{
        System.out.println("aa");
        ctx.disconnect();
    }
}
